var siteInfo = require("../siteinfo.js");
var t = siteInfo.siteroot, 

o = (getApp(), function(o, e) {
    var n = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}, i = arguments.length > 4 ? arguments[4] : void 0, a = arguments.length > 5 && void 0 !== arguments[5] && arguments[5], s = !(arguments.length > 6 && void 0 !== arguments[6]) || arguments[6], d = getApp();
    if (void 0 !== n.validate) try {
        Object.keys(n.validate).forEach(function(t) {
            if ("" === n[t] || null === n[t] || void 0 === n[t]) throw new Error(n.validate[t]);
        });
    } catch (t) {
        return wx.showToast({
            title: t.message,
            icon: "none"
        }), !1;
    }
    var r = {}, g = wx.getStorageSync("userToken") || "";
    console.log('------url------',t + e);
    n.token = g, n.shop_id = siteInfo.shop_id, r.token = g,r.shop_id = siteInfo.shop_id, wx.request({
        url: t + e,
        data: n,
        dataType: "json",
        header: r,
        method: o,
        success: function(t) {
            if (s && wx.hideLoading(), 404 === t.statusCode) return wx.showToast({
                title: "页面丢失~请稍后再试",
                icon: "none"
            }), !1;
            if (t.statusCode >= 500) return wx.showToast({
                title: "系统异常，请稍后再试~",
                icon: "none"
            }), !1;
            if (1 === (t = t.data).code) i(t.data, t.msg); else {
                if (0 === t.code) return wx.showToast({
                    title: t.msg,
                    icon: "none"
                }), a && i(t.data), !1;
                401 === t.code && (wx.setStorageSync("token", null), d.globalData.userinfo = {}, 
                wx.showToast({
                    title: "请先登录",
                    icon: "none",
                    success: function() {
                        d.login();
                    }
                }));
            }
        },
        fail: function(t) {
            return s && wx.hideLoading(), wx.showToast({
                title: "系统异常，请稍后再试~",
                icon: "none"
            }), !1;
        }
    });
});

module.exports = {
    get: function(t) {
        var e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, n = arguments.length > 2 && void 0 !== arguments[2] && arguments[2], i = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : function(t) {}, a = arguments.length > 4 && void 0 !== arguments[4] && arguments[4], s = t + JSON.stringify(e), d = wx.getStorageSync(s), r = !0;
        d ? (r = !1, i && i(JSON.parse(d))) : wx.showLoading({
            title: "加载中，请稍等"
        }), o("GET", t, e, n, function(t) {
            if (JSON.stringify(t) == d) return !1;
            wx.setStorageSync(s, JSON.stringify(t)), i && i(t);
        }, a, r);
    },
    post: function(t) {
        var e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, n = arguments.length > 2 && void 0 !== arguments[2] && arguments[2], i = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : function(t) {}, a = arguments.length > 4 && void 0 !== arguments[4] && arguments[4];
        wx.showLoading({
            title: "加载中，请稍等",
            mask: !0
        }), o("POST", t, e, n, i, a);
    }
};